#pragma once

#include "sqlite/sqlite3.h"
#pragma comment(lib, "sqlite3.lib")

namespace umtl
{
	template< typename CharType >
	struct sqlite_wrapper
	{
		static bool open(sqlite3 **db, CharType const* dbFileName) { return sqlite3_open( dbFileName, db ) == SQLITE_OK; }
		static bool prepare(sqlite3 *db, sqlite3_stmt **stmt, CharType const* query ) { return ( sqlite3_prepare_v2( db, query, -1, stmt, 0 ) == SQLITE_OK ); }
		static void bind_text( sqlite3_stmt *stmt, int paramIdx, CharType const* param ) { sqlite3_bind_text(stmt, paramIdx + 1, param, -1, SQLITE_STATIC); }
		static CharType const * name( sqlite3_stmt *stmt, int columIdx ) { return sqlite3_column_name(stmt, columIdx); }
		static CharType const * text( sqlite3_stmt *stmt, int columIdx ) { return sqlite3_column_text(stmt, columIdx); }
	};

	template<>
	struct sqlite_wrapper< wchar_t >
	{
		static bool open(sqlite3 **db, wchar_t const* dbFileName) { return sqlite3_open16( dbFileName, db ) == SQLITE_OK; }
		static bool prepare(sqlite3 *db, sqlite3_stmt **stmt, wchar_t const* query ) { return ( sqlite3_prepare16_v2( db, query, -1, stmt, 0 ) == SQLITE_OK ); }
		static void bind_text( sqlite3_stmt *stmt, int paramIdx, wchar_t const* param ) { sqlite3_bind_text16(stmt, paramIdx + 1, param, -1, SQLITE_STATIC); }
		static wchar_t const * name( sqlite3_stmt *stmt, int columIdx ) { return static_cast<wchar_t const*>( sqlite3_column_name16(stmt, columIdx) ); }
		static wchar_t const * text( sqlite3_stmt *stmt, int columIdx ) { return static_cast<wchar_t const*>( sqlite3_column_text16(stmt, columIdx) ); }
	};
}

